package channelHandler

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commEntity"
	"gitee.com/fierce_wolf/go-fox-edge-common/edgeEntity"
	"go-fox-edge-channel-tcp-server-v2/channelEngine/scriptEngine"
)

type OperateEntityNotify struct {
}

func (e *OperateEntityNotify) Notify(updateTime int64, addMap map[string]commEntity.IEntity, delSet map[string]commEntity.IEntity, mdyMap map[string]commEntity.IEntity) {
	for _, entity := range mdyMap {
		operateEntity := entity.(*edgeEntity.OperateEntity)

		if operateEntity.EngineType != "JavaScript" {
			continue
		}
		if operateEntity.ServiceType != "channel" {
			continue
		}

		// 检查：是否有配置该设备类型的JS引擎
		if len(scriptEngine.GetScriptEngines(operateEntity.Manufacturer, operateEntity.DeviceType)) == 0 {
			continue
		}

		scriptEngine.ReloadScriptEngine(operateEntity.Manufacturer, operateEntity.DeviceType, operateEntity)
	}
}
